package com.hanrui.android.fragment.message.audit.dispatch;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.DispatchDocDetailBean;
import com.hanrui.android.net.contract.message.audit.dispatch.DispatchDocDetailContract;
import com.hanrui.android.net.presenter.message.audit.dispatch.DispatchDocDetailPresenter;

import butterknife.BindView;

/**
 * 发文审批基本信息
 *
 */

public class DispatchDocDetailFragment extends BaseFragment<DispatchDocDetailPresenter> implements DispatchDocDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.duty_company)
    TextView dutyCompany;
    @BindView(R.id.assign_body)
    TextView assignBody;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.base_data)
    TextView baseData;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.money_meet)
    TextView moneyMeet;
    @BindView(R.id.wind_meet)
    TextView windMeet;
    @BindView(R.id.party_meet)
    TextView partyMeet;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;


    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_dispatchdocdetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.dispatchDocBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static DispatchDocDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        DispatchDocDetailFragment fragment = new DispatchDocDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void dispatchDocBizDetail(final DispatchDocDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getUserName()+"的发文单");
            subheadTitle.setText(data.getDetail().getCreateDate());
            name.setText(data.getDetail().getTitle());
            thingTitle.setText(data.getDetail().getSend());
            dutyPeople.setText(data.getDetail().getUserNames());
            time.setText(data.getDetail().getCopyto());
            leaders.setText(data.getDetail().getUserName());
            dutyCompany.setText(data.getDetail().getUrgency());
            assignBody.setText(data.getDetail().getCopies());
            from.setText(data.getDetail().getDense());
            baseData.setText(data.getDetail().getLeader());
            voteMeet.setText(data.getDetail().getCheckd());
            moneyMeet.setText(data.getDetail().getReview());
            windMeet.setText(data.getDetail().getOpentype());
            partyMeet.setText(data.getDetail().getNoStart());


            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                enclosureNum.setText("["+data.getFiles().size()+"]");
                enclosure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(getActivity(),data.getFiles());

                    }
                });

            		}
        }

    }
}
